﻿#pragma once
#include "ZuiLib.h"
#include "LRefObject.h"
#include "ZDragControl.h"

namespace ZuiLib {

/// 控件类
// @classmod Control

//lua创建的对象被lua引用，如果从c++中获取的对象则不引用，如果lua需要引用则可以调用ref来引用
class LControl :public LRefObject<ZControl>
{
public:

	///获取类名
	//@function getClass
	//@treturn string className
	int getClass(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetClass());
	}

	///获取名称
	//@function getName
	//@treturn string name
	int getName(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetName().GetString());
	}

	///设置名称
	//@function setName
	//@tparam string name
	int setName(LuaFuncState& L)
	{
		pThis->SetName(L.arg(0).toString());
		return 0;
	}


	///获取控件flags
	//@function getControlFlags
	//@treturn int flags
	int getControlFlags(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetControlFlags());
	}

	///激活控件
	//@function activate
	int activate(LuaFuncState& L)
	{
		pThis->Activate();
		return 0;
	}

	///获取父控件
	//@function getParent
	//@return control
	int getParent(LuaFuncState& L)
	{
		return L.lreturn(LuaClass<ZControl>::cToLua(&L,pThis->GetParent()));
	}


	///获取文本
	//@function getText
	//@return text
	int getText(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetText());
	}

	///设置文本
	//@function setText
	//@param text
	int setText(LuaFuncState& L)
	{
		pThis->SetText(L.arg(0).toString());
		return 0;
	}

	///设置文本会进行翻译转换
	//@function setTransText
	//@param text
	int setTransText(LuaFuncState& L)
	{
		pThis->SetTransText(L.arg(0).toString());
		return 0;
	}

	int getBkColor(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetBkColor());
	}

	int setBkColor(LuaFuncState& L)
	{
		pThis->SetBkColor(toColor(L.arg(0)));
		return 0;
	}

	int getBkImage(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetBkImage());
	}

	int setBkImage(LuaFuncState& L)
	{
		pThis->SetBkImage(L.arg(0).toString());
		return 0;
	}

	int getFocusBorderColor(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetFocusBorderColor());
	}

	int setFocusBorderColor(LuaFuncState& L)
	{
		pThis->SetFocusBorderColor(toColor(L.arg(0)));
		return 0;
	}

	int getBorderSize(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetBorderSize());
	}

	int setBorderSize(LuaFuncState& L)
	{
		pThis->SetBorderSize(L.arg(0).toUInt());
		return 0;
	}
	int getBorderColor(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetBorderColor());
	}

	int setBorderColor(LuaFuncState& L)
	{
		pThis->SetBorderColor(toColor(L.arg(0)));
		return 0;
	}

	int isDelayDestroy(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsDelayDestroy());
	}

	int checkKeyState(LuaFuncState& L)
	{
		return L.lreturn(pThis->CheckKeyState((KeyState)L.arg(0).toUInt()));
	}

	int getPos(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L,pThis->GetPos()));
	}

	int setPos(LuaFuncState& L)
	{
		pThis->SetPos(toRect(L.arg(0)));
		return 0;
	}

	int getWidth(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetWidth());
	}

	int getHeight(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetHeight());
	}

	int getX(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetX());
	}

	int getY(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetY());
	}

	int getPadding(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L, pThis->GetPadding()));
	}
	int setPadding(LuaFuncState& L)
	{
		pThis->SetPadding(toRect(L.arg(0)));
		return 0;
	}
	int getFixedXY(LuaFuncState& L)
	{
		return L.lreturn(toLua(&L, pThis->GetFixedXY()));
	}
	int setFixedXY(LuaFuncState& L)
	{
		pThis->SetFixedXY(toSize(L.arg(0)));
		return 0;
	}
	int getFixedWidth(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetFixedWidth());
	}

	int setFixedWidth(LuaFuncState& L)
	{
		pThis->SetFixedWidth(L.arg(0).toUInt());
		return 0;
	}

	int getFixedHeight(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetFixedHeight());
	}

	int setFixedHeight(LuaFuncState& L)
	{
		pThis->SetFixedHeight(L.arg(0).toUInt());
		return 0;
	}

	int getMinWidth(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetMinWidth());
	}

	int setMinWidth(LuaFuncState& L)
	{
		pThis->SetMinWidth(L.arg(0).toUInt());
		return 0;
	}

	int getMaxWidth(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetMaxWidth());
	}

	int setMaxWidth(LuaFuncState& L)
	{
		pThis->SetMaxWidth(L.arg(0).toUInt());
		return 0;
	}

	int getMinHeight(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetMinHeight());
	}

	int setMinHeight(LuaFuncState& L)
	{
		pThis->SetMinHeight(L.arg(0).toUInt());
		return 0;
	}
	int getMaxHeight(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetMaxHeight());
	}

	int setMaxHeight(LuaFuncState& L)
	{
		pThis->SetMaxHeight(L.arg(0).toUInt());
		return 0;
	}

	int setToolTip(LuaFuncState& L)
	{
		pThis->SetToolTip(L.arg(0).toString());
		return 0;
	}

	int setTransToolTip(LuaFuncState& L)
	{
		pThis->SetTransToolTip(L.arg(0).toString());
		return 0;
	}

	int getToolTip(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetToolTip());
	}


	int setShortcut(LuaFuncState& L)
	{
		pThis->SetShortcut(L.arg(0).toInt());
		return 0;
	}

	int getShortcut(LuaFuncState& L)
	{
		return L.lreturn((int)pThis->GetShortcut());
	}


	int setContextMenuUsed(LuaFuncState& L)
	{
		pThis->SetContextMenuUsed(L.arg(0).toBool());
		return 0;
	}

	int isContextMenuUsed(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsContextMenuUsed());
	}


	int setUserData(LuaFuncState& L)
	{
		pThis->SetUserData(L.arg(0).toString());
		return 0;
	}

	int getUserData(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetUserData());
	}

	int setTag(LuaFuncState& L)
	{
		pThis->SetTag(L.arg(0).toInt());
		return 0;
	}

	int getTag(LuaFuncState& L)
	{
		return L.lreturn((long)pThis->GetTag());
	}

	int setVisible(LuaFuncState& L)
	{
		pThis->SetVisible(L.arg(0).toBool());
		return 0;
	}

	int isVisible(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsVisible());
	}

	int setEnabled(LuaFuncState& L)
	{
		pThis->SetEnabled(L.arg(0).toBool());
		return 0;
	}

	int isEnabled(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsEnabled());
	}

	int setMouseEnabled(LuaFuncState& L)
	{
		pThis->SetMouseEnabled(L.arg(0).toBool());
		return 0;
	}

	int isMouseEnabled(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsMouseEnabled());
	}
	int setKeyboardEnabled(LuaFuncState& L)
	{
		pThis->SetKeyboardEnabled(L.arg(0).toBool());
		return 0;
	}

	int isKeyboardEnabled(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsKeyboardEnabled());
	}


	int setFocus(LuaFuncState& L)
	{
		pThis->SetFocus();
		return 0;
	}

	int isFocused(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsFocused());
	}

	int setFloat(LuaFuncState& L)
	{
		pThis->SetFloat(L.arg(0).toBool());
		return 0;
	}

	int isFloat(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsFloat());
	}

	int invalidate(LuaFuncState& L)
	{
		if (L.arg(0).isTable())
		{
			RECT rc = toRect(L.arg(0));
			pThis->Invalidate(&rc);
		}
		else
			pThis->Invalidate();
		return 0;
	}

	int isUpdateNeeded(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsUpdateNeeded());
	}

	int needUpdate(LuaFuncState& L)
	{
		pThis->NeedUpdate();
		return 0;
	}
	int needParentUpdate(LuaFuncState& L)
	{
		pThis->NeedParentUpdate();
		return 0;
	}

	int isInited(LuaFuncState& L)
	{
		return L.lreturn(pThis->IsInited());
	}

	int getAlpha(LuaFuncState& L)
	{
		return L.lreturn(pThis->GetAlpha());
	}

	int setAlpha(LuaFuncState& L)
	{
		pThis->SetAlpha(L.arg(0).toInt());
		return 0;
	}

	int getWindow(LuaFuncState& L)
	{
		return L.lreturn(LuaClass<ZWindow>::cToLua(&L,pThis->GetWindow()));
	}

	int beginDrag(LuaFuncState& L)
	{
		ZRefCountedPtr<ZDragPopupControl> control = new ZRefCountedObject<ZDragPopupControl>();
		control->BeginDrag(pThis);
		return 0;
	}

	BEGIN_MAP_FUNC(LControl)
	DECLARE_FUNC(getClass),
	DECLARE_FUNC(getName),
	DECLARE_FUNC(setName),
	DECLARE_FUNC(getControlFlags),
	DECLARE_FUNC(activate),
	DECLARE_FUNC(getParent),
	DECLARE_FUNC(getText),
	DECLARE_FUNC(setText),
	DECLARE_FUNC(setTransText),
	DECLARE_FUNC(getBkColor),
	DECLARE_FUNC(setBkColor),
	DECLARE_FUNC(getBkImage),
	DECLARE_FUNC(setBkImage),
	DECLARE_FUNC(getFocusBorderColor),
	DECLARE_FUNC(setFocusBorderColor),
	DECLARE_FUNC(getBorderSize),
	DECLARE_FUNC(setBorderSize),
	DECLARE_FUNC(getBorderColor),
	DECLARE_FUNC(setBorderColor),
	DECLARE_FUNC(isDelayDestroy),
	DECLARE_FUNC(checkKeyState),
	DECLARE_FUNC(getPos),
	DECLARE_FUNC(setPos),
	DECLARE_FUNC(getWidth),
	DECLARE_FUNC(getHeight),
	DECLARE_FUNC(getX),
	DECLARE_FUNC(getY),
	DECLARE_FUNC(getPadding),
	DECLARE_FUNC(setPadding),
	DECLARE_FUNC(getFixedXY),
	DECLARE_FUNC(setFixedXY),
	DECLARE_FUNC(getFixedWidth),
	DECLARE_FUNC(setFixedWidth),
	DECLARE_FUNC(getFixedHeight),
	DECLARE_FUNC(setFixedHeight),
	DECLARE_FUNC(getMinWidth),
	DECLARE_FUNC(setMinWidth),
	DECLARE_FUNC(getMaxWidth),
	DECLARE_FUNC(setMaxWidth),
	DECLARE_FUNC(getMinHeight),
	DECLARE_FUNC(setMinHeight),
	DECLARE_FUNC(getMaxHeight),
	DECLARE_FUNC(setMaxHeight),
	DECLARE_FUNC(setToolTip),
	DECLARE_FUNC(setTransToolTip),
	DECLARE_FUNC(getToolTip),
	DECLARE_FUNC(setShortcut),
	DECLARE_FUNC(getShortcut),
	DECLARE_FUNC(setContextMenuUsed),
	DECLARE_FUNC(isContextMenuUsed),
	DECLARE_FUNC(setUserData),
	DECLARE_FUNC(getUserData),
	DECLARE_FUNC(setTag),
	DECLARE_FUNC(getTag),
	DECLARE_FUNC(setVisible),
	DECLARE_FUNC(isVisible),
	DECLARE_FUNC(setEnabled),
	DECLARE_FUNC(isEnabled),
	DECLARE_FUNC(setMouseEnabled),
	DECLARE_FUNC(isMouseEnabled),
	DECLARE_FUNC(setKeyboardEnabled),
	DECLARE_FUNC(isKeyboardEnabled),
	DECLARE_FUNC(setFocus),
	DECLARE_FUNC(isFocused),
	DECLARE_FUNC(setFloat),
	DECLARE_FUNC(isFloat),
	DECLARE_FUNC(invalidate),
	DECLARE_FUNC(isUpdateNeeded),
	DECLARE_FUNC(needUpdate),
	DECLARE_FUNC(needParentUpdate),
	DECLARE_FUNC(isInited),
	DECLARE_FUNC(getAlpha),
	DECLARE_FUNC(setAlpha),
	DECLARE_FUNC(getWindow),
	DECLARE_FUNC(beginDrag),
	
	END_MAP_FUNC


	BEGIN_MAP_CONST
	DECLARE_CONST("KS_CTRL", KS_CTRL),
	DECLARE_CONST("KS_ALT", KS_ALT),
	DECLARE_CONST("KS_SHIFT", KS_SHIFT),
	DECLARE_CONST("KS_GUI", KS_GUI),
	END_MAP_CONST
};

}//namespace

